package service;

import dao.RentMapper;
import org.apache.ibatis.session.SqlSession;
import pojo.Rent;
import utils.MybatisUtils;

import java.util.List;

public class RentService {
    //查询
    public List<Rent> getRent(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        RentMapper rentMapper = sqlSession.getMapper(RentMapper.class);
        List<Rent> rents = rentMapper.getRent();
        sqlSession.close();
        return rents;
    }
    //添加
    public int addRent(Rent rent){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        RentMapper rentMapper = sqlSession.getMapper(RentMapper.class);
        int result = rentMapper.addRent(rent);

        sqlSession.commit();
        return result;
    }
    //id查询
    public Rent queryId(int id){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        RentMapper rentMapper = sqlSession.getMapper(RentMapper.class);
        Rent rent = rentMapper.queryId(id);

        sqlSession.close();
        return rent;
    }
    //id删除
    public int deleteRent(int id){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        RentMapper rentMapper = sqlSession.getMapper(RentMapper.class);
        int result = rentMapper.deleteRent(id);
        sqlSession.commit();
        sqlSession.close();
        return result;
    }
}
